﻿import lite.mobile.lib.utils.Delegate;
import lite.mobile.lib.components.UStage;
import lite.mobile.lib.components.UComponent;
import lite.mobile.lib.components.IUComponent;
import lite.mobile.lib.components.skin.ICollectionSkin;

/**
 * @author alibber
 * @ 初始化 起始类
 */
class lite.mobile.lib.WeeUIMain {
	private static var instance : WeeUIMain;

	public static function getInstance() : WeeUIMain {
		if (instance == null) {
			instance = new WeeUIMain();
		}
		return instance;
	}

	private var _$root : MovieClip;

	public function initRoot(value : MovieClip) : Void {
		trace("//- : 设置root..." + value);
		if (!_$root) {
			trace("//- : 创建root...");
			if (!value) {
				trace("//- : 赋值root...");
				value = _root;
			}
			_$root = value;
			enterFrame();
		}
	}

	public function getRoot() : MovieClip {
		trace("//- : 获取root...");
		return _$root;
	}

	private var _stageUI : IUComponent ;

	public function getStageUI() : IUComponent {
		if(!_stageUI) {
			_stageUI = new UStage();
			trace("//- : 获取UStage...");
		}
		return _stageUI;
	}

	private function enterFrame() : Void {
		_$root.onEnterFrame = Delegate.create(this, onEnterFrame);
	}

	private var nowFocus : String ;

	private function onEnterFrame(event) : Void {
		if(nowFocus != Selection.getFocus()) {
			nowFocus = Selection.getFocus()
			trace("当前焦点:  " + Selection.getFocus());
		}
	}
}